package controller;

import config.Interceptor.PassToken;
import entity.Shoptype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import service.impl.Shoptypeserviceimpl;
import utils.CommonRetumType;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/shoptype")
public class shoptypecontroller{
    @Resource
    Shoptypeserviceimpl shoptypeserviceimpl;

//    对应分类中商品查询
    @RequestMapping("/typelist")
    @PassToken
    public CommonRetumType selcetfind(@RequestParam("id") Integer id)
    {

        return CommonRetumType.create(shoptypeserviceimpl.selectByPrimaryKey(id),"查询成功");
    }

    //查子类
    @RequestMapping("/typelistbyid")
    @PassToken
    public CommonRetumType typefind(@RequestParam(value = "id",required = true) Integer id)
    {
        ArrayList<Shoptype> arrayList = new ArrayList<>();
        HashMap<String, HashMap<String,List<Shoptype>>> hashMap1 = new HashMap<>();
        Shoptype shoptype = shoptypeserviceimpl.selectByPrimaryKey(id);
        if (shoptype.getTypeid() == null){
            return CommonRetumType.create(shoptype,"查询成功");
        }else {
            HashMap<String,List<Shoptype>> hashMap = new HashMap<>();
            List<Shoptype> shoptypeList = shoptypeserviceimpl.listarray(shoptype.getTypeid());
            for (Shoptype shoptype1: shoptypeList)
            {
                arrayList.add(shoptype1);
            }
            hashMap.put("childlist",arrayList);
            return CommonRetumType.create(hashMap,"查询成功");
        }


    }
}
